#include<queue>
using std::queue;


struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};



class Solution {
public:
    bool isSymmetric(TreeNode* root) {
        return isTwoTreeSymmetric(root->left, root->right);
    }

    bool isTwoTreeSymmetric(TreeNode* left, TreeNode* right) {
        if ((left && !right) || (!left && right)) return false;
        else if (!left && !right) return true;
        else if (left->val == right->val) return isTwoTreeSymmetric(left->left, right->right) && isTwoTreeSymmetric(left->right, right->left);
        return false;
    }
};